﻿using UnityEngine;
using System.Collections;

public class triggerAtaque : MonoBehaviour {
	public bool orientar=false;

	void OnTriggerEnter(Collider obj){
		if(obj.CompareTag("Player")){
			SendMessage("atacar",SendMessageOptions.DontRequireReceiver);
			//Debug.Log(obj.transform.right.x + " - " + transform.right.x);
			if(orientar && 
			   ((obj.transform.position.x>transform.position.x && obj.transform.right.x + transform.right.x != 2) ||
			   (obj.transform.position.x<transform.position.x && obj.transform.right.x + transform.right.x != 0))
			   )
			
				transform.Rotate(new Vector3(0,180,0));
				/*
				Vector3 escala = transform.localScale;
			escala.x*=-1;
				transform.localScale=escala;}*/
		}
	}

	void OnTriggerStay(Collider obj){
		if(obj.CompareTag("Player") && orientar)
		if((obj.transform.position.x>transform.position.x && obj.transform.right.x + transform.right.x != 2) ||
		   (obj.transform.position.x<transform.position.x && obj.transform.right.x + transform.right.x != 0)
		   )
			transform.Rotate(new Vector3(0,180,0));
		
	}

	void OnTriggerExit(Collider obj){
		if(obj.CompareTag("Player"))
			SendMessage("detenerAtaque",SendMessageOptions.DontRequireReceiver);
	}

	// Use this for initialization
	void Start () {
	
	}
	
	// Update is called once per frame
	void Update () {
	
	}
}
